﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Aga.GestionDeArchivos.Services;
using Aga.GestionDeArchivos.Common;
using Aga.GestionDeArchivos.Web.Models.Setup;
using System.Configuration;

namespace Aga.GestionDeArchivos.Web.Controllers
{
    public class SetupController : ControllerBase
    {
        //
        // GET: /Setup/

        public ActionResult Index()
        {
            SetupModel model = new SetupModel 
            {
                IsSetupComplete = false
            };

            return View(model);
        }

        [HttpPost]
        public ActionResult Index(SetupModel model)
        {
            UserService service = new UserService();

            try 
            {
                service.ValidateUser("admin", model.AdminPassword);
            
                model.IsSetupComplete = true;
            }
            catch (ArgumentException ex)
            {
                model.IsSetupComplete = false;

                ModelState.AddModelError("AdminPassword", ex.Message);
            }

            return View(model);
        }
    }
}
